#include <iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<stdio.h>
#include<unordered_set>
using namespace std;


#include <stdio.h>
bool isZ(int const& re)
{
	if (re ==0) { return 0; }
	if (re <= 3) { return 1; }
	for (int i = 2; i < re; i++)
	{
		if (re % i == 0) { return 0; }
	}
	return 1;
}
int main()

{
	string s;
	int n;
	cin >> n;

	int* app = new int[n];
	long long* dp = new long long[n];
	for (int i = 0; i < n; i++)
	{
		cin>>app[i];
	}

	for (int i = 0; i < n; i++)
	{
		if (i==0)
		{
			dp[i]= app[i];
			continue;
		}
		if (i == 1)
		{
			dp[i] = max(app[i],app[0]);
			continue;
		}
		if (i == 2)
		{
			dp[i] = max(app[i]+dp[i-2], dp[i-1]);
			continue;
		}
		else
		{
			dp[i] = max(app[i] + dp[i - 2], app[i] + dp[i - 3]);
		}
	}
	cout << *max_element(dp, dp + n);
	//cout << dp[n-1];
}